#ifndef PYTABLES_H_
#define PYTABLES_H_

#include <hdf5.h>

#include <iostream>
#include <map>
#include <string>

#include "table.hpp"
#include "table_reader.hpp"
#include "table_writer.hpp"
#include "table_exception.hpp"

namespace pyt {
  template <class T> table<T>* open_table(const std::string& fname, 
					  const std::string& tblname,
					  const std::string mode="r",
					  const std::string title="untitled table", 
					  const hsize_t expected_rows=0,
					  unsigned int comp_level=0) 
  {
    if ((mode == "r") || (mode == "R"))
      return new table_reader<T>(fname, tblname);
    else if ((mode == "w") || (mode == "W"))
      return new table_writer<T>(fname, tblname, title, expected_rows, comp_level); 
    else {
      std::string msg = "Invalid mode specified: ";
      msg += mode;
      throw table_exception(msg);
    }
  } 

  template <class T> table<T>* open_table(const std::string& fname, 
					  const std::string& tblname, 
					  const char* mode="r",
					  const std::string& title="untitled table", 
					  const hsize_t expected_rows=0,
					  unsigned int comp_level=0) 
  {
    std::string _mode    = mode;
    return open_table<T>(fname, tblname, _mode, title, expected_rows, comp_level);
  } 

  template <class T> table<T>* open_table(const std::string& fname, 
					  const std::string& tblname, 
					  const char* mode="r",
					  const char* title="untitled table", 
					  const hsize_t expected_rows=0, 
					  unsigned int comp_level=0)  
  {
    std::string _mode    = mode;
    std::string _title   = title;
    return open_table<T>(fname, tblname, _mode, _title, expected_rows, comp_level);
  } 


  template <class T> table<T>* open_table(const std::string& fname, 
					  const char* tblname, 
					  const char* mode="r",
					  const char* title="untitled table", 
					  const hsize_t expected_rows=0,
					  unsigned int comp_level=0)  
  {
    std::string _tblname = tblname;
    std::string _mode    = mode;
    std::string _title   = title;
    return open_table<T>(fname, _tblname, _mode, _title, expected_rows, comp_level);
  } 

  template <class T> table<T>* open_table(const char* fname, 
					  const char* tblname, 
					  const char* mode="r",
					  const char* title="untitled table", 
					  const hsize_t expected_rows=0,
					  unsigned int comp_level=0)  
  {
    std::string _fname   = fname;
    std::string _tblname = tblname;
    std::string _mode    = mode;
    std::string _title   = title;
    return open_table<T>(_fname, _tblname, _mode, _title, expected_rows, comp_level);
  } 

}


#endif //PYTABLES_H_


 



  



     
   

    
